import Vue from "vue";
import App from "./App.vue";
import router from "./router";
import store from "./store";
import Axios from 'axios'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'

Vue.use(ElementUI);
Vue.prototype.$axios = Axios;
Vue.config.productionTip = false;

const mvue = new Vue({
  router,
  store,
  render: h => h(App)
}).$mount("#app");

// 拦截Axios发起的所有请求，通过dispatch修改isLoading为true
$axios.interceptors.request.use(
  config => {
    mvue.$store.dispatch('loadingStart'); // 显示loading组件
    return config;
  },
  err => {
    return Promise.reject(err);
  });
//拦截Axios发起的所有响应，通过dispatch修改isLoading为false
$axios.interceptors.response.use((config) => {
  mvue.$store.dispatch('loadingEnd');
  return config
});
